﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:custom="clr-namespace:Feedbook.Custom"
	xmlns:model="clr-namespace:Feedbook.Model"
	xmlns:auto="clr-namespace:Feedbook.Automation"
	mc:Ignorable="d"
	x:Class="Feedbook.FeedView"
    x:ClassModifier="internal"
	x:Name="UserControl"
	d:DesignWidth="640" d:DesignHeight="480" DataContextChanged="UserControl_DataContextChanged">
    <UserControl.Resources>

        <auto:FriendlyDateTimeConverter x:Key="FriendlyDateTimeConverter"/>
        <auto:AbsoluteUriConverter x:Key="AbsoluteUriConverter"/>

        <DataTemplate x:Key="EnclosureTemplate" DataType="{x:Type model:Enclosure}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <StackPanel Cursor="Hand" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,2">
                    <Button x:Name="EnclosureButton" IsEnabled="{Binding IsDownloaded}" ToolTipService.ShowOnDisabled="True" ToolTip="{Binding Length, Converter={StaticResource BytesToReadableSizeConverter}}" Focusable="False" Width="Auto" Height="Auto" Template="{DynamicResource TransparentFBButtonTemplate}">
                        <Image Source="{Binding Type, Converter={StaticResource ContentTypeToImageUriConverter}}" Height="24"/>
                    </Button>
                    <Image Margin="2,0,0,0" x:Name="image" Height="24" Source="..\Images\download.png" Width="22" Visibility="Hidden" RenderTransformOrigin="0.5,1" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Image.RenderTransform>
                            <TranslateTransform/>
                        </Image.RenderTransform>
                        <Image.ToolTip>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding DownloadPercentage}"/>
                                <TextBlock Text="%"/>
                            </StackPanel>
                        </Image.ToolTip>
                    </Image>
                </StackPanel>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsDownloading}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard Storyboard.TargetName="image" >
                                <DoubleAnimation Storyboard.TargetProperty="RenderTransform.Y" To="-5" Duration="0:0:0.35" AutoReverse="True" RepeatBehavior="Forever"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <Setter Property="Visibility" Value="Visible" TargetName="image"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <Storyboard x:Key="FeedTransitionStory">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="FeedReader">
                <EasingDoubleKeyFrame KeyTime="0" Value="-30">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="FeedReader">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="textBlock">
                <EasingDoubleKeyFrame KeyTime="0" Value="-30">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="stackPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="stackPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="-30">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:1.1" Value="0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock1">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="textBlock1">
                <EasingDoubleKeyFrame KeyTime="0" Value="-30">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="0">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Border BorderThickness="1" CornerRadius="4" Background="{DynamicResource ContrastBrush}" Padding="10,10,5,5">

            <Grid x:Name="ContentGrid" VerticalAlignment="Top" Hyperlink.RequestNavigate="HyperLink_RequestNavigate" Visibility="Hidden">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <TextBlock x:Name="textBlock" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="WrapWithOverflow" TextTrimming="CharacterEllipsis" FontSize="16" Margin="0,0,31,0" RenderTransformOrigin="0.5,0.5">
        			<TextBlock.RenderTransform>
        				<TransformGroup>
        					<ScaleTransform/>
        					<SkewTransform/>
        					<RotateTransform/>
        					<TranslateTransform/>
        				</TransformGroup>
        			</TextBlock.RenderTransform>
                    <Hyperlink TextDecorations="None" NavigateUri="{Binding Link.HRef}">
                        <Run Text="{Binding Title}" Foreground="{StaticResource FeedTitleBrush}"/>
                    </Hyperlink>
                </TextBlock>
                <Button HorizontalAlignment="Right" d:LayoutOverrides="Height" Template="{DynamicResource TransparentButtonTemplate}" Cursor="Hand" Width="32" VerticalAlignment="Center" Margin="0,-7,2,-7" Click="SendEmailClick">
                    <Image Source="/Feedbook;component/Images/email_send.png" Stretch="Fill"/>
                </Button>
                <Rectangle Grid.Row="1" Height="1" RadiusX="1" RadiusY="0.5" VerticalAlignment="Center" HorizontalAlignment="Stretch" Width="Auto" StrokeThickness="0" Margin="0,4,4,4" Visibility="Collapsed">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="1,0.526" StartPoint="0,0.526">
                            <GradientStop Color="#170000FF" Offset="1"/>
                            <GradientStop Color="#FF7171FF" Offset="0.86"/>
                            <GradientStop Color="#FF8585FF" Offset="0.14"/>
                            <GradientStop Color="#150000FF"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Border BorderBrush="#4D000000" BorderThickness="0,1,0,0" VerticalAlignment="Center" Height="2" Background="White" Margin="0,4,4,4" Grid.Row="1"/>
                <StackPanel x:Name="stackPanel" TextElement.Foreground="Gray"  Grid.Row="2" Orientation="Horizontal" Grid.RowSpan="1" Margin="0,-3,0,0" RenderTransformOrigin="0.5,0.5" >
                    <StackPanel.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </StackPanel.RenderTransform>
                    <TextBlock Margin="0" HorizontalAlignment="Left" Text="{Binding Updated, Converter={StaticResource FriendlyDateTimeConverter}}" VerticalAlignment="Center" FontSize="12"/>
                    <TextBlock Margin="0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="12" Text=" "/>
                    <TextBlock Margin="0" HorizontalAlignment="Left" Text="{Binding Author.Name, StringFormat=by \{0\}}" VerticalAlignment="Center" FontSize="12"/>
                    <TextBlock x:Name="textBlock1" Margin="6,0,0,0" Cursor="Hand" ToolTip="Go to full post . . ." RenderTransformOrigin="0.5,0.5" ><TextBlock.RenderTransform>
        					<TransformGroup>
        						<ScaleTransform/>
        						<SkewTransform/>
        						<RotateTransform/>
        						<TranslateTransform/>
        					</TransformGroup>
        				</TextBlock.RenderTransform>
                        <Hyperlink x:Name="externalHyperlink" TextDecorations="None" NavigateUri="{Binding Link.HRef}"><InlineUIContainer>
        						<Image Source="/Feedbook;component/Images/link.png" Margin="0,2,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Height="22" />
        					</InlineUIContainer></Hyperlink></TextBlock>
                </StackPanel>
                <FlowDocumentScrollViewer Grid.Row="3" x:Name="FeedReader"  IsToolBarVisible = "True" VerticalScrollBarVisibility =  "Auto">
                	<FlowDocumentScrollViewer.Resources>
                		<Style TargetType="{x:Type Hyperlink}">
                			<Setter Property="Foreground" Value="{StaticResource FeedTitleBrush}" />
						</Style>           	
					</FlowDocumentScrollViewer.Resources>
                	                    <FlowDocumentScrollViewer.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </FlowDocumentScrollViewer.RenderTransform>
                </FlowDocumentScrollViewer>               
                <ListBox Grid.Row="4" x:Name="enclosureListBox" BorderBrush="{x:Null}" ItemsSource="{Binding Enclosures}" ItemTemplate="{StaticResource EnclosureTemplate}" VerticalAlignment="Top" Background="{x:Null}"/>
            </Grid>
        </Border>
        <!--<custom:MediaPlayer x:Name="MediaPlayer" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="1" Visibility="Collapsed"/>-->
    </Grid>
</UserControl>